import 'package:get/get.dart';
import 'package:school_assistant_m/store/login_store.dart';
import 'package:school_assistant_m/utils/base_api.dart';

/// 用户相关API
class UserApi extends BaseApi {
  // Map updataForm = {
  //   'username': '',
  //   'password': '',
  // };
  /// 有秘钥修改密码
  Future<Response> updatePwd(form) async {
    // FormData formData = FormData(Map<String, dynamic>.from(form));
    Map updataForm = {
      'username': form['username'],
      'password': form['newPassword'],
    };
    print('-------------我是formData');
    print(updataForm);
    // 判断是否有token
    LoginStore store = LoginStore();
    String token = await store.getToken();
    int id = await store.getUserId();
    Response response;
    if (token == '') {
      // response = await put('/users/'+id.toString()+'/',form);
      response = await put('/users/'+id.toString()+'/',updataForm);
    } else {
      // response = await put('/users/'+id.toString()+'/',form);
      response = await put('/users/'+id.toString()+'/',updataForm);
    }
    print('---------------------我是response.body');
    print(response.body);
    print(response.statusCode);
    print(response.statusText);
    // return response.body;
    var data = response.body;
    return Response(
      statusCode: response.statusCode,
      statusText: response.statusText,
      body: data,
    );
  }
}